// pages/detectRecList/detectRecList.js
var api = require('../../utils/request')
Page({
    data: {
        selected: [],
        startTime:'',
        endTime:'',
        idCardName:'',
        pageNumber:1,
        beanList:[],
        totalPageNum:1,
    },
    onLoad: function (options) {

    }, 
    onShow: function () {
        if(wx.getStorageSync('info')){
            this.search();
		}
    },    
    search(){
        this.setData({
            pageNumber:1,
            beanList:[]
        })
        this.getDetectRecList()
    },
    getDetectRecList(){
		if(!wx.getStorageSync('info')){
			wx.showToast({
			  title: '请登录账号！',
			  icon:"none"
			})
			return;
		}
        let taht = this;
        let {pageNumber,idCardName,startTime,endTime} = this.data;
		api.post({
            apiCode: "IReaderManageService.getDetectRecList",
            params:{
                detectRecQuery: {
                    conditionType: [],
                    endTime: endTime,
                    idCardName: idCardName,
                    pageNumber: pageNumber,
                    pageSize: 10,
                    sortType: [],
                    startTime: startTime,
                    telephone: "",
                    userUid: wx.getStorageSync("info").userUid
                }
            }
		}).then(res => {
			if (res.code == 0) {
                let arr = taht.data.beanList.concat(res.data.beanList);
                taht.setData({
                    beanList:arr,
                    totalPageNum:res.data.totalPageNum
                })
                if(!taht.data.beanList.length){
                    wx.showToast({
                        icon: "none",
                        title: "没有更多数据啦！",
                    })
                }
			} else {
				wx.showToast({
					icon: "none",
					title: res.msg,
				})
			}
		});
    },   
    bindStartDateChange: function(e) {
        // console.log('picker发送选择改变，携带值为', e.detail.value)
        this.setData({
            startTime: e.detail.value
        })
    },
    bindEndDateChange: function(e) {
        // console.log('picker发送选择改变，携带值为', e.detail.value)
        this.setData({
            endTime: e.detail.value
        })
    }, 
    getInputusername(data){
        this.setData({
            idCardName:data.detail.value
        })
    }, 
    delStartTime(){
        this.setData({
            startTime:''
        })
    },
    delEndTime(){
        this.setData({
            endTime:''
        })
    },  
    delName(){
        console.log("Sdas")
        this.setData({
            idCardName:''
        })
    }, 
    onHide: function () {
        this.setData({
            startTime:'',
            endTime:'',
            idCardName:'',
            pageNumber:1,
            beanList:[],
        })
    },
    onReachBottom: function () {
        console.log("sd");
        let {pageNumber, totalPageNum} = this.data;
        this.setData({
            pageNumber: pageNumber+1
        })
        if(this.data.pageNumber <= totalPageNum){
            this.getDetectRecList();
        }

    },
    onShareAppMessage: function () {

    }
})